package tool

import "strconv"

type Item struct {
	Key string

	Val string
}

type MapSorter []Item

func (ms MapSorter) Len() int {
	return len(ms)
}

func (ms MapSorter) Less(i, j int) bool {
	iv, _ := strconv.Atoi(ms[i].Key)
	jv, _ := strconv.Atoi(ms[j].Key)
	return iv < jv // 按值排序
}
func (ms MapSorter) Swap(i, j int) {
	ms[i], ms[j] = ms[j], ms[i]
}

func NewMapSorter(m map[string]string) MapSorter {

	ms := make(MapSorter, 0, len(m))

	for k, v := range m {

		ms = append(ms, Item{k, v})

	}
	return ms
}
